package cn.ylhx.venue.mobilePay.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;



/*@Controller
public class PrePayPage {
	@RequestMapping(value = "prePayPage", method = { RequestMethod.GET })
	public String jsPay(HttpServletRequest request, HttpServletResponse response) throws Exception {
	    AuthAccessToken authAccessToken = null;
	    String code = request.getParameter("code");//可用redis保存
	    if(code==null){
	         return null;
	    }
	    String state = request.getParameter("state");
	    if(state.equals(MD5Util.MD5Encode("ceshi", ""))){
	        AuthTokenParams authTokenParams = new AuthTokenParams();
	        authTokenParams.setAppid("your appid");
	        authTokenParams.setSecret("your secret");
	        authTokenParams.setCode(code);
	        authAccessToken = oAuthService.getAuthAccessToken(authTokenParams, ACCESS_TOKEN_URL);  
	    }
	    if(authAccessToken!=null){
	        logger.info("正在支付的openid=" + authAccessToken.getOpenid());
	    }
	    return "system/wxpay/testpay";
	}
	
	/**
     * 微信内H5调起支付
     *
     * @param request
     * @param response
     * @param openId
     * @return
     * @throws Exception
     */
   /* @ResponseBody
    @RequestMapping("jspay")
    public JsPayResult jsPay(HttpServletRequest request, HttpServletResponse response, String openId) throws Exception {
        JsPayResult result = null;
        logger.info("****正在支付的openId****" + openId);
        // 统一下单
        String out_trade_no = PayUtil.createOutTradeNo();
        int total_fee = 1; // 产品价格1分钱,用于测试
        String spbill_create_ip = HttpReqUtil.getRemortIP(request);
        logger.info("支付IP" + spbill_create_ip);
        String nonce_str = PayUtil.createNonceStr(); // 随机数据
        //参数组装
        UnifiedOrderParams unifiedOrderParams = new UnifiedOrderParams();
        unifiedOrderParams.setAppid(WeChatConfig.APP_ID);// 必须
        unifiedOrderParams.setMch_id(WeChatConfig.MCH_ID);// 必须
        unifiedOrderParams.setOut_trade_no(out_trade_no);// 必须
        unifiedOrderParams.setBody("支付测试");// 必须
        unifiedOrderParams.setTotal_fee(total_fee); // 必须
        unifiedOrderParams.setNonce_str(nonce_str); // 必须
        unifiedOrderParams.setSpbill_create_ip(spbill_create_ip); // 必须
        unifiedOrderParams.setTrade_type("JSAPI"); // 必须
        unifiedOrderParams.setOpenid(openId);
        unifiedOrderParams.setNotify_url(WeChatConfig.NOTIFY_URL);// 异步通知url
        // 统一下单 请求的Xml(正常的xml格式)
        String unifiedXmL = wechatPayService.abstractPayToXml(unifiedOrderParams);////签名并入service
        // 返回<![CDATA[SUCCESS]]>格式的XML
        String unifiedOrderResultXmL = HttpReqUtil.HttpsDefaultExecute(HttpReqUtil.POST_METHOD,WeChatConfig.UNIFIED_ORDER_URL, null, unifiedXmL);
        // 进行签名校验
        if (SignatureUtil.checkIsSignValidFromWeiXin(unifiedOrderResultXmL)) {
            String timeStamp = PayUtil.createTimeStamp();
            //统一下单响应
            UnifiedOrderResult unifiedOrderResult = XmlUtil.getObjectFromXML(unifiedOrderResultXmL, UnifiedOrderResult.class);
            /**** 用map方式进行签名 ****/
            // SortedMap<Object, Object> signMap = new TreeMap<Object,
            // Object>();
            // signMap.put("appId", WeiXinConfig.APP_ID); // 必须
            // signMap.put("timeStamp", timeStamp);
            // signMap.put("nonceStr", nonceStr);
            // signMap.put("signType", "MD5");
            // signMap.put("package", "prepay_id=" + prepay_id);
            // String paySign = SignatureUtil.createSign(signMap, key, SystemConfig.CHARACTER_ENCODING);
           /* result = new JsPayResult();
            result.setAppId(WeChatConfig.APP_ID);
            result.setTimeStamp(timeStamp);
            result.setNonceStr(unifiedOrderResult.getNonce_str());//直接用返回的
            /**** prepay_id 2小时内都有效，再次支付方法自己重写 ****/
          /*  result.setPackageStr("prepay_id=" + unifiedOrderResult.getPrepay_id());
            /**** 用对象进行签名 ****/
          /*  String paySign = SignatureUtil.createSign(result, WeChatConfig.API_KEY, SystemConfig.CHARACTER_ENCODING);
            result.setPaySign(paySign);
            result.setResultCode("SUCCESS");
        } else {
            logger.info("签名验证错误");
        }
        /**** 返回对象给页面 ****/
       /* return result;
    }

}*/
